﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Oplaco.Core.DAL;
using Oplaco.Core.BusinessLogicLayer;
using System.Data;
using System.Web;

namespace Oplaco.Web.DTO
{
    /// <summary>
    /// Advertisment Data Transfer Object
    /// </summary>
    /// <remarks>
    /// It is important to keep in mind that the data binding mechanism in ASP.NET was designed for binding to flat data sources, 
    /// and although it can be used to bind hierarchically, it may not always be the best choice for rendering data that is truly hierarchical in nature.
    /// </remarks>
    /// <see cref="http://msdn.microsoft.com/en-us/library/92t2ye13.aspx"/>
    /// <seealso cref="http://msdn.microsoft.com/en-us/library/aa478959.aspx"/>
    public class CachedAdvertisment : ICacheableDataTransferObject<CachedAdvertisment>
    {
        #region Property
        public int Id { get; set; }
        public int MemberId { get; set; }
        public int Rank { get; set; }
        public int PreviewImageId { get; set; }
        public int CategoryId { get; set; }

        public DateTime DateCreated { get; set; }
        public DateTime DateApproved { get; set; }
        public DateTime DateExpired { get; set; }
        public DateTime PublishDate { get; set; }

        public string CurrencyPrice { get; set; }
        public decimal Price { get; set; }
        public string AdvertismentType { get; set; }
        public string Title { get; set; }
        public string CategoryName { get; set; }
        /// <summary>
        /// CategoryPath: full blown category names (MainCategory, ChildCategory)
        /// </summary>
        public string CategoryPath { get; set; }
        public string Description { get; set; }
        public string Url { get; set; }


        public ICollection<CachedAdvertisment> ChildCollection { get; set; }
        public bool HasChilds { get { return (this.ChildCollection == null) ? false : true; } }
        public AdLevel AdvertismentLevel { get; set; }
        public AdStatus Status { get; set; }
        #endregion

        public CachedAdvertisment(int id, int memberid, int categoryid, string title, string categorytitle, string categoryPath, decimal price, int adtype, int adlevel, int adstatus, DateTime creationdate, DateTime approveddate, DateTime expiredate, string description, string url, int previewimageid)
        {
            this.Id = id;
            this.MemberId = memberid;            
            this.DateApproved = approveddate;
            this.DateCreated = creationdate;
            this.DateExpired = expiredate;
            this.PublishDate = approveddate; //publishdate for system to keep track of things.
            this.Title = title;
            this.CategoryName = categorytitle;
            this.Description = description;
            this.Url = url;
            this.CurrencyPrice = price.ToString("C");
            this.Price = Math.Round(price, 2);
            this.AdvertismentType = Enum.GetName(typeof(AdType), adtype);
            this.AdvertismentLevel = (AdLevel)adlevel;
            this.Status = (AdStatus)adstatus;
            this.PreviewImageId = previewimageid;
            this.CategoryId = categoryid;
            this.CategoryPath = categoryPath;
            
        }


        
    }
}
